package nl.infodation.emr.pricingservice.dao;

import java.util.List;

import nl.infodation.emr.pricingservice.data.DomainRuleSearchItem;
import nl.infodation.emr.pricingservice.entity.DomainRule;
import nl.infodation.emr.pricingservice.entity.Environment;

import com.googlecode.genericdao.search.SearchResult;

/**
 * @author SUCCESS\tungo
 *
 */
public interface DomainRuleDAO extends DAO <DomainRule, Long> {

	public static String SEARCH_AND_PAGING_SQL = "SELECT p FROM DomainRule p"
			+ " WHERE p.busLine LIKE :busLine"
			+ " AND p.promotionValue LIKE :promotionValue"
			+ " AND p.ruleName LIKE :ruleName"
			+ " AND p.country LIKE :country"
			+ " AND p.languageValue LIKE :languageValue"
			+ " AND p.environment.environmentId = :environmentId"
			+ " AND p.promotionActive = :promotionActive";
	
	public static String SEARCH_AND_COUNT_SQL = "SELECT COUNT(p) FROM DomainRule p"
			+ " WHERE p.busLine LIKE :busLine"
			+ " AND p.promotionValue LIKE :promotionValue"
			+ " AND p.ruleName LIKE :ruleName"
			+ " AND p.country LIKE :country"
			+ " AND p.languageValue LIKE :languageValue"
			+ " AND p.environment.environmentId = :environmentId"
			+ " AND p.promotionActive = :promotionActive";

	public static String SEARCH_IDS_SQL = "SELECT p.domainRuleId FROM DomainRule p"
			+ " WHERE p.busLine LIKE :busLine"
			+ " AND p.promotionValue LIKE :promotionValue"
			+ " AND p.ruleName LIKE :ruleName"
			+ " AND p.country LIKE :country"
			+ " AND p.languageValue LIKE :languageValue"
			+ " AND p.environment.environmentId = :environmentId"
			+ " AND p.promotionActive = :promotionActive";
	
	public static String FIND_BY_BUS_LINE_SQL = "SELECT p FROM DomainRule p WHERE p.busLine LIKE :busLine";
	
	public static String FIND_BY_BUS_LINE_AND_ENV_SQL = "SELECT p FROM DomainRule p WHERE p.busLine LIKE :busLine AND p.environment.environmentId = :environmentId";
	
	public static String FIND_BY_NAME_AND_ENV_SQL = "SELECT p FROM DomainRule p WHERE p.ruleName LIKE :ruleName AND p.environment.environmentId = :environmentId";
	
	public static String FIND_BY_NAME_SQL = "SELECT p FROM DomainRule p WHERE p.ruleName LIKE :ruleName and p.promotionActive = :promotionActive ";
	
	/**
	 * Search & paging DomainRule 
	 * @param searchData
	 * @param startPage
	 * @param pageSize
	 * @return
	 */
	SearchResult<DomainRule> searchInPage(DomainRuleSearchItem searchData, int startPage, int pageSize);
	
	/**
	 * Find list of DomainRule's ID
	 * @param searchData
	 * @return
	 */
	List<Long> findIDs(DomainRuleSearchItem searchData);
	
	/**
	 * Find DomainRule by Business Line
	 * @param busLine
	 * @return
	 */
	List<DomainRule> findByBusLine(String busLine);
	
	/**
	 * Find DomainRule by Business Line & Environment
	 * @param busLine
	 * @param environmentId
	 * @return
	 */
	List<DomainRule> findByBusLine(String busLine, Integer environmentId);
	
	/**
	 * Find DomainRule by name
	 * @param name
	 * @param environmentId
	 * @return
	 */
	List<DomainRule> findByName(String name, Integer environmentId);
	
	/**
	 * Find DomainRule by name
	 * @param name
	 * @return
	 */
	List<DomainRule> findByName(String name);
	
	/**
	 * Copy checked DomainRule to another environment
	 * @param superBusLine
	 * @param busLine
	 * @param env
	 * @param clean
	 * @param IDs
	 * @return
	 */
	Boolean copyToEnvironment(String superBusLine, String busLine, Environment env, Boolean clean, List<Long> IDs);

}
